package com.push.web.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.push.common.annotation.Log;
import com.push.common.core.controller.BaseController;
import com.push.common.core.domain.AjaxResult;
import com.push.common.enums.BusinessType;
import com.push.web.domain.BizArticleAppendix;
import com.push.web.service.IBizArticleAppendixService;
import com.push.common.utils.poi.ExcelUtil;
import com.push.common.core.page.TableDataInfo;

/**
 * 附件管理Controller
 *
 * @author yanxi
 * @date 2022-08-30
 */
@RestController
@RequestMapping("/information/appendix")
public class BizArticleAppendixController extends BaseController
{
    @Autowired
    private IBizArticleAppendixService bizArticleAppendixService;

    /**
     * 查询附件管理列表
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizArticleAppendix bizArticleAppendix)
    {
        startPage();
        List<BizArticleAppendix> list = bizArticleAppendixService.selectBizArticleAppendixList(bizArticleAppendix);
        return getDataTable(list);
    }

    /**
     * 导出附件管理列表
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:export')")
    @Log(title = "附件管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizArticleAppendix bizArticleAppendix)
    {
        List<BizArticleAppendix> list = bizArticleAppendixService.selectBizArticleAppendixList(bizArticleAppendix);
        ExcelUtil<BizArticleAppendix> util = new ExcelUtil<BizArticleAppendix>(BizArticleAppendix.class);
        return util.exportExcel(list, "附件管理数据");
    }

    /**
     * 获取附件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizArticleAppendixService.selectBizArticleAppendixById(id));
    }

    /**
     * 新增附件管理
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:add')")
    @Log(title = "附件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizArticleAppendix bizArticleAppendix)
    {
        return toAjax(bizArticleAppendixService.insertBizArticleAppendix(bizArticleAppendix));
    }

    /**
     * 修改附件管理
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:edit')")
    @Log(title = "附件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizArticleAppendix bizArticleAppendix)
    {
        return toAjax(bizArticleAppendixService.updateBizArticleAppendix(bizArticleAppendix));
    }

    /**
     * 删除附件管理
     */
    @PreAuthorize("@ss.hasPermi('information:appendix:remove')")
    @Log(title = "附件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizArticleAppendixService.deleteBizArticleAppendixByIds(ids));
    }
}
